package com.formiaomiao.demain.controller;

import com.formiaomiao.demain.model.FollowBean;
import com.formiaomiao.demain.service.FollowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "/follow")
public class FollowController {

    @Autowired
    FollowService followService;

    /**
     * 查询关注人动态列表
     * @param id
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/selectFollow")
    private Object SelectFollow(@RequestParam(name = "id", required = false) Integer id,
                                @RequestParam(name = "pageNum", required = false) Integer pageNum,
                                @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        return followService.SelectFollow(id, pageNum, pageSize);
    }

    /**
     * 查询关注的人
     * @param id
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/selectUserFollow")
    private Object SelectUserFollow(@RequestParam(name = "id", required = false) Integer id,
                                @RequestParam(name = "pageNum", required = false) Integer pageNum,
                                @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        return followService.SelecetUserFollow(id, pageNum, pageSize);
    }

    /**
     * 查询粉丝
     * @param id
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/selectFansFollow")
    private Object SelectFansFollow(@RequestParam(name = "id", required = false) Integer id,
                                @RequestParam(name = "pageNum", required = false) Integer pageNum,
                                @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        return followService.SelecetFansFollow(id, pageNum, pageSize);
    }

    /**
     * 关注
     * @param id
     * @param toid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/insertFollow")
    private Object InsertFollow(@RequestParam(name = "id", required = false) Integer id,
                                @RequestParam(name = "toid", required = false) Integer toid){
        FollowBean bean = new FollowBean();
        bean.setFollowfrom(id);
        bean.setFollowto(toid);
        return followService.InsertFollow(bean);
    }

    /**
     * 取消关注
     * @param id
     * @param toid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deleteFollow")
    private Object DeleteFollow(@RequestParam(name = "id", required = false) Integer id,
                                @RequestParam(name = "toid", required = false) Integer toid){
        FollowBean bean = new FollowBean();
        bean.setFollowfrom(id);
        bean.setFollowto(toid);
        return followService.DeleteFollow(bean);
    }

    /**
     * 是否关注
     * @param id
     * @param toid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/CheckFollow")
    private Object CheckFollow(@RequestParam(name = "id", required = false) Integer id,
                               @RequestParam(name = "toid", required = false) Integer toid){
        FollowBean bean = new FollowBean();
        bean.setFollowfrom(id);
        bean.setFollowto(toid);
        return followService.CheckFollow(bean);
    }
}
